package com.chengqj;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.data.mongodb.MongoDatabaseFactory;
import org.springframework.data.mongodb.MongoTransactionManager;

@SpringBootApplication
public class TxMongodbApplication {

    public static void main(String[] args) {
        SpringApplication.run(TxMongodbApplication.class, args);
    }

    /**
     * 必須新建一个事务管理器
     * @param dbFactory
     * @return
     */
    @Bean
    MongoTransactionManager primaryMongoTransactionManager(MongoDatabaseFactory dbFactory) {
        return new MongoTransactionManager(dbFactory);
    }
}
